package de.fhtrier.mp.wollmaus.entity.player;

import java.text.DecimalFormat;

import org.newdawn.slick.Animation;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

public class PlayerAnimations {

	private static final int ANIMATION_TIMESTEP = 50;

	public final static int STAND_PICS = 82;
	public final static int RUN_PICS = 12;
	public final static int JUMP_PICS = 17;
	public final static int JUMPSTRAIGHT_PICS = 18;
	public final static int FALL_PICS = 9;

	private String[] stand;
	private String[] runRight;
	private String[] jumpRight;
	private String[] jumpStraightRight;
	private String[] fallRight;

	private Image[] standLeftImg = new Image[STAND_PICS];
	private Image[] standRightImg = new Image[STAND_PICS];
	private Image[] runRightImg = new Image[RUN_PICS];
	private Image[] runLeftImg = new Image[RUN_PICS];
	private Image[] jumpRightImg = new Image[JUMP_PICS];
	private Image[] jumpLeftImg = new Image[JUMP_PICS];
	private Image[] jumpStraightRightImg = new Image[JUMPSTRAIGHT_PICS];
	private Image[] jumpStraightLeftImg = new Image[JUMPSTRAIGHT_PICS];
	private Image[] fallRightImg = new Image[FALL_PICS];
	private Image[] fallLeftImg = new Image[FALL_PICS];

	public PlayerAnimations() {
		DecimalFormat df = new DecimalFormat("0000");

		// Stand - Ani
		stand = new String[STAND_PICS];
		for (int i = 0; i < STAND_PICS; i++) {
			stand[i] = "Files/player/stand/Stand" + df.format(i) + ".png";
		}

		// RunRight - Ani
		runRight = new String[RUN_PICS];
		for (int i = 0; i < RUN_PICS; i++) {
			runRight[i] = "Files/player/runRight/Lauf" + df.format(i) + ".png";
		}

		// JumpRight - Ani
		jumpRight = new String[JUMP_PICS];
		for (int i = 0; i < JUMP_PICS; i++) {
			jumpRight[i] = "Files/player/jumpSideRight/Sprung" + df.format(i) + ".png";
		}

		// JumpStraightRight - Ani
		jumpStraightRight = new String[JUMP_PICS];
		for (int i = 0; i < JUMP_PICS; i++) {
			jumpStraightRight[i] = "Files/player/jumpUpRight/Hochsprung" + df.format(i) + ".png";
		}

		// Fall - Ani
		fallRight = new String[FALL_PICS];
		for (int i = 0; i < FALL_PICS; i++) {
			fallRight[i] = "Files/player/fall/Sturz" + df.format(i) + ".png";
		}

		try {
			loadPictures();
		}
		catch (SlickException e) {
			e.printStackTrace();
		}
	}

	public void loadPictures() throws SlickException {
		for (int i = 0; i < STAND_PICS; i++) {
			standRightImg[i] = new Image(stand[i]);
			standLeftImg[i] = standRightImg[i].getFlippedCopy(true, false);
		}
		
		for (int i = 0; i < RUN_PICS; i++) {
			runRightImg[i] = new Image(runRight[i]);
			runLeftImg[i] = runRightImg[i].getFlippedCopy(true, false);
		}

		for (int i = 0; i < JUMP_PICS; i++) {
			jumpRightImg[i] = new Image(jumpRight[i]);
			jumpLeftImg[i] = jumpRightImg[i].getFlippedCopy(true, false);
		}

		for (int i = 0; i < JUMP_PICS; i++) {
			jumpStraightRightImg[i] = new Image(jumpStraightRight[i]);
			jumpStraightLeftImg[i] = jumpStraightRightImg[i].getFlippedCopy(true, false);
		}

		for (int i = 0; i < FALL_PICS; i++) {
			fallRightImg[i] = new Image(fallRight[i]);
			fallLeftImg[i] = fallRightImg[i].getFlippedCopy(true, false);
		}
	}
	
	/*
	 * convert Images to Animations
	 */

	public Animation createStandLeftAnimation() {
		Animation ani = new Animation(standLeftImg, ANIMATION_TIMESTEP);
		return ani;
	}

	public Animation createStandRightAnimation() {
		Animation ani = new Animation(standRightImg, ANIMATION_TIMESTEP);
		return ani;
	}
	
	public Animation createRunRightAnimation() {
		Animation ani = new Animation(runRightImg, ANIMATION_TIMESTEP);
		return ani;
	}

	public Animation createRunLeftAnimation() {
		Animation ani = new Animation(runLeftImg, ANIMATION_TIMESTEP);
		return ani;
	}

	public Animation createJumpRightAnimation() {
		Animation ani = new Animation(jumpRightImg, ANIMATION_TIMESTEP);
		return ani;
	}

	public Animation createJumpLeftAnimation() {
		Animation ani = new Animation(jumpLeftImg, ANIMATION_TIMESTEP);
		return ani;
	}

	public Animation createJumpStraightRightAnimation() {
		Animation ani = new Animation(jumpStraightRightImg, ANIMATION_TIMESTEP);
		return ani;
	}

	public Animation createJumpStraightLeftAnimation() {
		Animation ani = new Animation(jumpStraightLeftImg, ANIMATION_TIMESTEP);
		return ani;
	}

	public Animation createFallRightAnimation() {
		Animation ani = new Animation(fallRightImg, ANIMATION_TIMESTEP);
		return ani;
	}

	public Animation createFallLeftAnimation() {
		Animation ani = new Animation(fallLeftImg, ANIMATION_TIMESTEP);
		return ani;
	}

}
